namespace IMPlant.Core.Web.Control.GridViewFunction
{
    using IMPlant.Core.Web.Control;
    using IMPlant.Core.Web.Control.Helper;
    using System;
    using System.Collections.Generic;
    using System.Web.UI.WebControls;

    public class ColumnSpanFunction : ExtendFunction
    {
        public ColumnSpanFunction()
        {
        }

        public ColumnSpanFunction(IMPlant.Core.Web.Control.GridView grid) : base(grid)
        {
        }

        private void _grid_RowDataBoundDataRow(object sender, GridViewRowEventArgs e)
        {
            if (!string.IsNullOrEmpty(base._grid.ColumnSpan))
            {
                string[] strArray = Common.ReplaceCommaChars(base._grid.ColumnSpan).Split(new char[] { ';' });
                int length = strArray.Length;
                Dictionary<int, int> dictionary = new Dictionary<int, int>();
                for (int i = 0; i < length; i++)
                {
                    int num3;
                    int num4;
                    string str = strArray[i].ToString();
                    if (!int.TryParse(str.Substring(0, str.IndexOf(",")), out num3))
                    {
                        num3 = 0;
                    }
                    if (!int.TryParse(str.Substring(str.IndexOf(",") + 1), out num4))
                    {
                        num4 = 0;
                    }
                    dictionary.Add(num3, num4);
                }
                int count = e.Row.Cells.Count;
                foreach (KeyValuePair<int, int> pair in dictionary)
                {
                    if ((pair.Key >= 0) && (pair.Key <= (count - 1)))
                    {
                        e.Row.Cells[pair.Key].Attributes.Add("colSpan", pair.Value.ToString());
                    }
                }
            }
        }

        protected override void Execute()
        {
            base._grid.RowDataBoundDataRow += new IMPlant.Core.Web.Control.GridView.RowDataBoundDataRowHandler(this._grid_RowDataBoundDataRow);
        }
    }
}

